﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Boomerang.Common.Configuration;

namespace Boomerang.Management.UIForms
{
    public partial class WizardFormBase : Form
    {
        protected WizardFormType type;

        protected Organization org;

        public WizardFormBase()
        {
            InitializeComponent();
        }

        public WizardFormBase(string Title, WizardFormType type, Organization organization)
        {
            InitializeComponent();
            this.Text = Title;
            this.org = organization;
            this.type = type;
            InitButtons();
        }

        #region Wizard Buttons Management
        private void InitButtons()
        {
            switch (type)
            {
                case WizardFormType.Start:
                    buttonFinish.Visible = false;
                    buttonPrevious.Visible = false;
                    break;
                case WizardFormType.Middle:
                    buttonFinish.Visible = false;
                    break;
                case WizardFormType.Finish:
                    buttonNext.Visible = false;
                    break;
                default:
                    break;
            }
        }

        public delegate void ButtonEventHandler(Form form, WizardButtonType buttonType);

        public event ButtonEventHandler OnWizardButtonClick;       

        private void buttonPrevious_Click(object sender, EventArgs e)
        {
            if(!InternalButtonClick(WizardButtonType.Previous)) return;
            if (OnWizardButtonClick != null)
                OnWizardButtonClick(this, WizardButtonType.Previous);
        }
        
        private void buttonNext_Click(object sender, EventArgs e)
        {
            if (!InternalButtonClick(WizardButtonType.Next)) return;
            if (OnWizardButtonClick != null)
                OnWizardButtonClick(this, WizardButtonType.Next);
        }

        private void buttonFinish_Click(object sender, EventArgs e)
        {
            if (!InternalButtonClick(WizardButtonType.Finish)) return;
            if (OnWizardButtonClick != null)
                OnWizardButtonClick(this, WizardButtonType.Finish);
        }

        private void buttonCancel_Click(object sender, EventArgs e)
        {
            if (!InternalButtonClick(WizardButtonType.Cancel)) return;
            if (OnWizardButtonClick != null)
                OnWizardButtonClick(this, WizardButtonType.Cancel);
        }

        protected virtual bool InternalButtonClick(WizardButtonType wizardButtonType)
        {
            return true; //Cancel event returning false
        }
        #endregion

    }

    public enum WizardFormType
    {
        Start,
        Middle,
        Finish
    }

    public enum WizardButtonType
    {
        Previous,
        Next,
        Finish,
        Cancel
    }
}
